//
// Created by xili on 2024/8/31 14:33.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumDeletions(vector<int> &nums) {
        int mx = max_element(nums.begin(), nums.end()) - nums.begin();
        int mn = min_element(nums.begin(), nums.end()) - nums.begin();
        int n = nums.size();
        return min(mn > mx ? n + 2 - mn + mx : n + 2 - mx + mn,
                   min(mn > mx ? mn + 1 : mx + 1, mn > mx ? n - mx + 1 : n - mn + 1));
    }
};